# coding: utf-8
from typing import List

from pydantic import BaseModel, Field

from .public import AssertDataModel, FuncStepModel


class WebTestCaseModel(BaseModel):
    """
    Web测试用例
    WebTestCase represents a web test case.
    """
    module_name: str = Field(alias='模块名称')
    ui_name: str = Field(alias='UI名称')
    case_name: str = Field(alias='用例名称')
    case_description: str = Field('', alias='用例描述')
    case_tags: str = Field('', alias='用例标签')
    is_run: bool = Field(True, alias='是否运行')
    is_new_window: bool = Field(False, alias='新窗口')
    window_index: int = Field(0, alias='窗口索引')
    steps: List[FuncStepModel] = Field(..., alias='执行步骤')
    assert_data: List[AssertDataModel] = Field([], alias='断言')
    extract: dict = Field(None, alias='提取数据')


def web_test_case_validate(data: dict) -> WebTestCaseModel:
    """
    验证 WebTestCaseModel 数据
    Validate WebTestCaseModel data.
    """
    try:
        case = WebTestCaseModel(**data)
        return case
    except Exception as e:
        raise ValueError(f"数据校验失败: {e}")
